package org.ht.global;

import java.sql.SQLException;

import org.azj.dbOperatorComponent.IDbQueryOperation;
import org.azj.dbOperatorComponent.OperableTable;
import org.ht.database.DataBase;

public class DbTableFactory {
	private static IDbQueryOperation tbl_basic_info;
	private static IDbQueryOperation tbl_before_op;
	private static IDbQueryOperation tbl_mid_op;
	private static IDbQueryOperation tbl_post_op;

	public static IDbQueryOperation getDbTable(String tableName)
			throws SQLException {
		return getDbTable(DbTableNames.SchemaName, tableName);
	}

	public static IDbQueryOperation getDbTable(String schema, String tableName)
			throws SQLException {
		String fullName = schema + "." + tableName;
		if (fullName.equals(DbTableNames.FullTblBasicInfo)) {
			if (tbl_basic_info == null) {
				tbl_basic_info = new OperableTable(DataBase.getDataBase(),
						schema, tableName);
			}
			return tbl_basic_info;
		}
		if (fullName.equals(DbTableNames.FullTblBeforeOp)) {
			if (tbl_before_op == null) {
				tbl_before_op = new OperableTable(DataBase.getDataBase(),
						schema, tableName);
			}
			return tbl_before_op;
		}
		if (fullName.equals(DbTableNames.FullTblMidOp)) {
			if (tbl_mid_op == null) {
				tbl_mid_op = new OperableTable(DataBase.getDataBase(), schema,
						tableName);
			}
			return tbl_mid_op;
		}
		if (fullName.equals(DbTableNames.FullTblPostOp)) {
			if (tbl_post_op == null) {
				tbl_post_op = new OperableTable(DataBase.getDataBase(), schema,
						tableName);
			}
			return tbl_post_op;
		}
		return null;
	}
}
